$(() => {
    $("header>span").click(function () {
        $(".post").slideDown('slow');});
        $('.btn').click(() => {
            //获取标题,分类，内容
            let [title, selected, content] = [$('.title').val(), $('select').val(), $('.content').val()];
            if (title.length == 0) {
                alert('请输入标题');
                return
            } else if (selected == '请选择版块') {
                alert('请选择版块');
                console.log(selected);
                return
            } else if (content.length == 0) {
                alert('请输入评论内容');
                return
            } else {
                if (title.length == 0 && selected == '请选择版块' && content.length == 0) {
                    alert('请输入内容');
                    return
                } else {
                    // issue()//去发布内容咯
                    $(".post").slideUp('slow', () => {
                        let arr_pic = ["../images/tou01.jpg",
                            "../images/tou02.jpg",
                            "../images/tou03.jpg",
                            "../images/tou04.jpg"];
                        let index = Math.floor((Math.random() * arr_pic.length));
                        let li=$("<li></li>");//创建发帖内容
                        let h5 = $("<h5>" + title + "</h5>");
                        li.append(h5).addClass("details");//追类
                        $('.title').val('');//清空标题
                        let pic = $("<img src= " + arr_pic[index] + " />");
                        li.append(pic);
                        let text =$("<p>版块: "+selected+"&nbsp;&nbsp&nbsp;&nbsp;</p>");
                        li.append(text);
                        $('select').val('请选择版块');//清空分类
                        let time="发表时间: "+getTime();
                        text.append(time);
                        let ul = $('section ul');//获得ul
                        ul.prepend(li);
                        $('.content').val('');//清空内容
                    });
                }
            }
           // return
        });


});

function getTime() {
        let date = new Date();
        let year = date.getFullYear();
        let month = date.getMonth() + 1;
        let monthDay = date.getDate();
        let weekDay = date.getDay();
        let hour = date.getHours();
        let min = date.getMinutes();
        let second = date.getSeconds();
        let milSecond = date.getMilliseconds();
        let nowTime = year + "-"
            + (month < 10 ? "0" + month : month) + "-"
            + (monthDay < 10 ? "0" + monthDay : monthDay) + "  "
            //+ weekDay + " "
            + (hour < 10 ? "0" + hour : hour) + ":"
            + (min < 10 ? "0" + min : min);
            //+ ":" + (second < 10 ? "0" + second : second)
            //+ ":" + milSecond;
    return nowTime
}